{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np \n",
    "from utils.time_df import TimeDF\n",
    "from utils.formula import cal_formula\n",
    "from utils.func import _FUNCTIONS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#以市盈率=市值/盈利为例\n",
    "dates=['2000','2001','2003']\n",
    "codes=['000001','000002','000003']\n",
    "\n",
    "values=[[1,2,3],[4,5,6],[7,8,9]]\n",
    "marketValue=pd.DataFrame(values,index=dates,columns=codes)\n",
    "\n",
    "profit=1\n",
    "profit_df=pd.DataFrame(profit,index=dates,columns=codes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000003</th>\n",
       "      <th>000002</th>\n",
       "      <th>000001</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000</th>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001</th>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2003</th>\n",
       "      <td>9.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      000003  000002  000001\n",
       "2000     3.0     2.0     1.0\n",
       "2001     6.0     5.0     4.0\n",
       "2003     9.0     8.0     7.0"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算市盈率\n",
    "data_dict={'a':marketValue,'b':profit_df}\n",
    "cal_formula('a/b',data_dict).df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'count' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-38-af862a9c7099>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#市盈率连续两期大于3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mdata_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'a'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mmarketValue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'b'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mprofit_df\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mcal_formula\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'count((a/b)>3,2)'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mdata_dict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mD:\\dir\\github\\sps\\utils\\formula.py\u001b[0m in \u001b[0;36mcal_formula\u001b[1;34m(formula, data_dict, _FUNCTIONS)\u001b[0m\n\u001b[0;32m      6\u001b[0m       \u001b[1;32mfor\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdata_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m             \u001b[0mdata_dict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTimeDF\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0meval\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mformula\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0m_FUNCTIONS\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mdata_dict\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<string>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'count' is not defined"
     ]
    }
   ],
   "source": [
    "#市盈率连续两期大于3\n",
    "data_dict={'a':marketValue,'b':profit_df}\n",
    "cal_formula('count((a/b)>3,2)',data_dict).df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'lag': <function utils.func.lag(Timedf, n)>,\n",
       " '_and': <function utils.func._and(*args)>,\n",
       " '_or': <function utils.func._or(*args)>,\n",
       " 'eq': <function utils.func.eq(Timedf, value)>,\n",
       " 'ge': <function utils.func.ge(Timedf, value)>,\n",
       " 'gt': <function utils.func.gt(Timedf, value)>,\n",
       " 'le': <function utils.func.le(Timedf, value)>,\n",
       " 'lt': <function utils.func.lt(Timedf, value)>}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_FUNCTIONS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'__name__': '__main__',\n",
       " '__doc__': 'Automatically created module for IPython interactive environment',\n",
       " '__package__': None,\n",
       " '__loader__': None,\n",
       " '__spec__': None,\n",
       " '__builtin__': <module 'builtins' (built-in)>,\n",
       " '__builtins__': <module 'builtins' (built-in)>,\n",
       " '_ih': ['',\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       "  \"cal_formula('a/b',data_dict)\",\n",
       "  \"a=cal_formula('a/b',data_dict)\",\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       "  \"a=cal_formula('a/b',data_dict)\",\n",
       "  'a.df',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  '_FUNCTIONS',\n",
       "  'locals()',\n",
       "  'globals()'],\n",
       " '_oh': {3: <utils.time_df.TimeDF at 0x291aededb48>,\n",
       "  7:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  9:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  14:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  19:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  23:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  26: {...}},\n",
       " '_dh': ['D:\\\\dir\\\\github\\\\sps'],\n",
       " 'In': ['',\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       "  \"cal_formula('a/b',data_dict)\",\n",
       "  \"a=cal_formula('a/b',data_dict)\",\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       "  \"a=cal_formula('a/b',data_dict)\",\n",
       "  'a.df',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       "  \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       "  \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       "  \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       "  '_FUNCTIONS',\n",
       "  'locals()',\n",
       "  'globals()'],\n",
       " 'Out': {3: <utils.time_df.TimeDF at 0x291aededb48>,\n",
       "  7:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  9:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  14:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  19:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  23:       000003  000002  000001\n",
       "  2000     3.0     2.0     1.0\n",
       "  2001     6.0     5.0     4.0\n",
       "  2003     9.0     8.0     7.0,\n",
       "  26: {...}},\n",
       " 'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x000002919ED63208>>,\n",
       " 'exit': <IPython.core.autocall.ZMQExitAutocall at 0x2919ede6a48>,\n",
       " 'quit': <IPython.core.autocall.ZMQExitAutocall at 0x2919ede6a48>,\n",
       " '_': {...},\n",
       " '__':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '___':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i': 'locals()',\n",
       " '_ii': '_FUNCTIONS',\n",
       " '_iii': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       " '_i1': 'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       " 'pd': <module 'pandas' from 'D:\\\\anaconda\\\\lib\\\\site-packages\\\\pandas\\\\__init__.py'>,\n",
       " 'np': <module 'numpy' from 'D:\\\\anaconda\\\\lib\\\\site-packages\\\\numpy\\\\__init__.py'>,\n",
       " 'TimeDF': utils.time_df.TimeDF,\n",
       " 'cal_formula': <function utils.formula.cal_formula(formula, data_dict, _FUNCTIONS={'lag': <function lag at 0x00000291AF780D38>, '_and': <function _and at 0x00000291AF780DC8>, '_or': <function _or at 0x00000291AF780E58>, 'eq': <function eq at 0x00000291AF780EE8>, 'ge': <function ge at 0x00000291AF780F78>, 'gt': <function gt at 0x00000291AF7680D8>, 'le': <function le at 0x00000291AF768048>, 'lt': <function lt at 0x00000291AF768168>})>,\n",
       " '_i2': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       " 'dates': ['2000', '2001', '2003'],\n",
       " 'codes': ['000001', '000002', '000003'],\n",
       " 'values': [[1, 2, 3], [4, 5, 6], [7, 8, 9]],\n",
       " 'marketValue':       000001  000002  000003\n",
       " 2000       1       2       3\n",
       " 2001       4       5       6\n",
       " 2003       7       8       9,\n",
       " 'profit': 1,\n",
       " 'profit_df':       000001  000002  000003\n",
       " 2000       1       1       1\n",
       " 2001       1       1       1\n",
       " 2003       1       1       1,\n",
       " 'data_dict': {'a': <utils.time_df.TimeDF at 0x291af892448>,\n",
       "  'b': <utils.time_df.TimeDF at 0x291af765988>},\n",
       " '_i3': \"cal_formula('a/b',data_dict)\",\n",
       " '_3': <utils.time_df.TimeDF at 0x291aededb48>,\n",
       " '_i4': \"a=cal_formula('a/b',data_dict)\",\n",
       " '_i5': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\\n\\ndata_dict={'a':marketValue,'b':profit_df}\",\n",
       " '_i6': \"a=cal_formula('a/b',data_dict)\",\n",
       " 'a': <utils.time_df.TimeDF at 0x291af89c948>,\n",
       " '_i7': 'a.df',\n",
       " '_7':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i8': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       " '_i9': \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       " '_9':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i10': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       " '_i11': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       " '_i12': 'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       " '_i13': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       " '_i14': \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       " '_14':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i15': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count(a/b>3,2)',data_dict).df\",\n",
       " '_i16': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       " '_i17': 'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       " '_i18': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       " '_i19': \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       " '_19':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i20': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       " '_i21': 'import pandas as pd \\nimport numpy as np \\nfrom utils.time_df import TimeDF\\nfrom utils.formula import cal_formula',\n",
       " '_i22': \"#以市盈率=市值/盈利为例\\ndates=['2000','2001','2003']\\ncodes=['000001','000002','000003']\\n\\nvalues=[[1,2,3],[4,5,6],[7,8,9]]\\nmarketValue=pd.DataFrame(values,index=dates,columns=codes)\\n\\nprofit=1\\nprofit_df=pd.DataFrame(profit,index=dates,columns=codes)\",\n",
       " '_i23': \"#计算市盈率\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('a/b',data_dict).df\",\n",
       " '_23':       000003  000002  000001\n",
       " 2000     3.0     2.0     1.0\n",
       " 2001     6.0     5.0     4.0\n",
       " 2003     9.0     8.0     7.0,\n",
       " '_i24': \"#市盈率连续两期大于3\\ndata_dict={'a':marketValue,'b':profit_df}\\ncal_formula('count((a/b)>3,2)',data_dict).df\",\n",
       " '_i25': '_FUNCTIONS',\n",
       " '_i26': 'locals()',\n",
       " '_26': {...},\n",
       " '_i27': 'globals()'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "globals()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
